<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>provider</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body ng-app="myApp">
<div ng-controller="demoCtrl">
    <div>
        <input ng-model="name"/>
    </div>
    <p ng-bind="name">Hello Everyone!</p>
    <ul>
        <li ng-repeat="user in users|filter:name" ng-bind="user.name"></li>
    </ul>
</div>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.min.js"></script>
<script>
    var app = angular.module('myApp', []);
    app.controller('demoCtrl', function ($scope, demoService) {
        $scope.name = 'liangfei';
        $scope.users = demoService.getUsers();
    });
    var Users = function () {
        this.getUsers = function () {
            var users = [{
                name: 'liangfei'
            }, {
                name: 'wanglin'
            }, {
                name: 'Jhon'
            }, {
                name: 'Jane'
            }];
            return users;
        }
    };
    app.provider('demoService', {
        $get: function () {
            function getUsers() {
                var users = [{
                    name: 'liangfei'
                }, {
                    name: 'wanglin'
                }, {
                    name: 'Jhon'
                }, {
                    name: 'Jane'
                }];
                return users;
            }

            return {
                getUsers: getUsers
            };
        }
    });
</script>
</body>
</html>